package com.micromsg.common.util;

import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
 * BASE64编码与解码
 */
public class Base64Utils {

    /**
     * 编码
     *
     * @param bstr
     * @return
     */
    public static String encode(byte[] bstr) {
        //String encode = Base64.encodeBase64String(bstr);
        String encode = new BASE64Encoder().encode(bstr);
        return encode;
    }

    /**
     * 解码
     *
     * @param str
     * @return
     */
    public static byte[] decode(String str) {
        byte[] bt = null;
        try {
            sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
            bt = decoder.decodeBuffer(str);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //byte[] bytes = Base64.decodeBase64(str);
        return bt;
    }
}
